var RemindModule = function () {
    
    var editable = function () {

        return {
            init: function () {
                var oTable = $('#modelEditable').dataTable({
                    "lengthMenu": [
                        [10, 15, 20, 50, -1],
                        [10, 15, 20, 50, "All"]
                    ],
                    "autoWidth":false,
                    "scrollX":true,
                    "displayLength": 10,
                    "language": {
                        "lengthMenu": "每页 _MENU_ 条记录",
                        "paginate": {
                            "previous": "上一页",
                            "next": "下一页"
                        },
                        "info" : "从 _START_ 到  _END_ 条，总记录为 _TOTAL_ 条",    
                        "infoEmpty" : "记录数为0",
                    },
                    "columnDefs": [
						{
						    'sortable': false,
						    "defaultContent": "",
						    "targets": [3]
						}            
                    ],
                    "columns": [
                       { "data": "productName" },
                       { "data": "setupTime" },
                       { "data": "createEndTime" }
                   ],
                   "filter" : false,
                   "sortable" : false,
                   "processing": false,
                   "serverSide": true,
                   "ajaxSource": ctx + "/remind/query",
                   "serverMethod": "post",
                   "fnRowCallback" : function(nRow, aData, displayIndex) {
                	   nRow.children[0].id = aData.id;
                	   
                	   var setupDate = aData.setupTime;
                	   setupDate = setupDate.substring(0, 10);
                	   $('td:eq(1)', nRow).html(setupDate);
                	   
                	   var endDate = aData.createEndTime;
                	   endDate = endDate.substring(0, 10);
                	   $('td:eq(2)', nRow).html(endDate);
                	   
                	   $('td:eq(3)', nRow).html('<a class="detail fa fa-bars fa-lg" title="明细" href="javascript:;"></a>');
                       return nRow;
                   },
                   "fnServerData" : function(ajaxSource, dataSet, fnCallback) {
	                   var json = "";
	                   var s;
	                   for (var i = 0; i < dataSet.length; i++) {
	                       s = dataSet[i];
	                   	   if (s.name == 'sEcho') {
	                   		   json = json + '"echo":' + s.value;
		                   } else if (s.name == 'iDisplayStart') {
		                	   json = json + ',"start":' + s.value;
		                   } else if (s.name == 'iDisplayLength') {
		                	   json = json + ',"pageSize":' + s.value;
		                   }
	                   }
	                   var form = $("form#queryForm").serializeJSON();
                   	   var js = form.replace('}', ',');
                   	   json = js + json + "}";
                       $.ajax({
                       	"contentType":"application/json; charset=UTF-8",
                           "dataType" : 'json',
                           "type" : "POST",
                           "url" : ajaxSource,
                           "data" : json,
                           "success" : fnCallback,
                           "error" : function(){
                        	   window.location.href=ctx + "/employee/login";
                           }
                       });
                   },
                });
                
                // 明细
                $('#modelEditable').on("click", "a.detail", (function (e) {
                    e.preventDefault();

                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                	window.location.href=ctx + '/remind/detail/' + id;
                }));
                
                $('#queryBtn').click(function(){
                	oTable.fnClearTable();
                });
            }

        };

    }();
    
    return {
        init: function () {
        	editable.init();
        }
    };
}();